package com.jianbing.north.service.impl;

import java.util.List;

import com.jianbing.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jianbing.north.mapper.NorthUserInfoMapper;
import com.jianbing.north.domain.NorthUserInfo;
import com.jianbing.north.service.INorthUserInfoService;

/**
 * 用户挑战进度表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@Service
public class NorthUserInfoServiceImpl implements INorthUserInfoService 
{
    @Autowired
    private NorthUserInfoMapper northUserInfoMapper;

    /**
     * 查询用户挑战进度表
     * 
     * @param userId 用户挑战进度表主键
     * @return 用户挑战进度表
     */
    @Override
    public NorthUserInfo selectNorthUserInfoByUserId(Long userId)
    {
        return northUserInfoMapper.selectNorthUserInfoByUserId(userId);
    }

    /**
     * 查询用户挑战进度表列表
     * 
     * @param northUserInfo 用户挑战进度表
     * @return 用户挑战进度表
     */
    @Override
    public List<NorthUserInfo> selectNorthUserInfoList(NorthUserInfo northUserInfo)
    {
        return northUserInfoMapper.selectNorthUserInfoList(northUserInfo);
    }

    /**
     * 新增用户挑战进度表
     * 
     * @param northUserInfo 用户挑战进度表
     * @return 结果
     */
    @Override
    public int insertNorthUserInfo(NorthUserInfo northUserInfo)
    {
        return northUserInfoMapper.insertNorthUserInfo(northUserInfo);
    }

    /**
     * 修改用户挑战进度表
     * 
     * @param northUserInfo 用户挑战进度表
     * @return 结果
     */
    @Override
    public int updateNorthUserInfo(NorthUserInfo northUserInfo)
    {
        return northUserInfoMapper.updateNorthUserInfo(northUserInfo);
    }

    /**
     * 批量删除用户挑战进度表
     * 
     * @param userIds 需要删除的用户挑战进度表主键
     * @return 结果
     */
    @Override
    public int deleteNorthUserInfoByUserIds(Long[] userIds)
    {
        return northUserInfoMapper.deleteNorthUserInfoByUserIds(userIds);
    }

    /**
     * 删除用户挑战进度表信息
     * 
     * @param userId 用户挑战进度表主键
     * @return 结果
     */
    @Override
    public int deleteNorthUserInfoByUserId(Long userId)
    {
        return northUserInfoMapper.deleteNorthUserInfoByUserId(userId);
    }

    @Override
    public Long getFraction(Long userId, Integer part) {
        Long p1Fraction = northUserInfoMapper.selectP1FractionByUserId(userId);
        Long p2Fraction = northUserInfoMapper.selectP2FractionByUserId(userId);
        if(part==null){
            return p1Fraction+p2Fraction;
        }else if (part==1){
            return p1Fraction;
        }else if(part==2){
            return p2Fraction;
        }
        return null;
    }

}
